package com.can.service.resource.impl;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.can.common.ITreeNodeAdapter;
import com.can.entity.Resource;
import com.can.entityDTO.TreeNode;
import com.can.mapper.ResourceMapper;
import com.can.service.BaseServiceImpl;
import com.can.service.resource.IResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Desription 用户资源service 实现类
 * @Author can
 * @Date 2018/10/19
 * @Version 1.0
 */
@Service
public class ResourceServiceImpl extends BaseServiceImpl<Resource> implements IResourceService {
    @Autowired
    private ResourceMapper mapper;


    @Override
    protected BaseMapper<Resource> getMapper() {
        return mapper;
    }

    @Override
    public List<TreeNode<Resource>> getTreeNodeList(Integer id) {
        return buildTreeList(mapper.getTreeList(id), new ITreeNodeAdapter<Resource>() {

            @Override
            public TreeNode<Resource> covert(Resource entity) {
                TreeNode<Resource> node = new TreeNode<Resource>();
                node.setId(entity.getId());
                node.setfId(entity.getfId());
                node.setLabel(entity.getName());
                node.setEntity(entity);
                return node;
            }
        });
    }

}
